/*
 * (C) Copyright 2016 Ymatou (http://www.ymatou.com/).
 * 
 * All rights reserved.
 */
package com.ymatou.iapi.userservice.parameter.enums;
/**
 * 应用来源
 * 
 * @author zhongwei
 *
 */
public enum AppSourceEnum {

    /**
     * 码头主站
     */
    MainSite(0, "MainSite"),

    /**
     * 手机APP
     */
    App(1, "App"),

    /**
     * Wap
     */
    Wap(2, "Wap"),

    /**
     * 阿里 - 废弃
     */
    Alipay(3, "Alipay"),

    /**
     * QQ - 废弃
     */
    QQ(4, "QQ"),

    /**
     * 新浪微博 - 废弃
     */
    Weibo(5, "Weibo"),

    /**
     * 码头APP - 废弃
     * 
     * 聚洋货APP已下线
     */
    MatouApp(6, "MatouApp"),

    /**
     * 商家后台
     */
    SellerSite(7, "SellerSite"),

    /**
     * 商家后台_APP
     */
    SellerApp(8, "SellerApp"),

    /**
     * 商家后台_Wap
     */
    SellerWap(9, "SellerWap"),

    /**
     * 微信小程序
     */
    WxApp(20, "WxApp"),

    /**
     * 未知来源
     */
    Other(100, "Other")
    ;

    private Integer code;

    private String message;

    AppSourceEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    /**
     * 通过错误码获取枚举项
     *
     * @param code
     * @return
     */
    public static AppSourceEnum getByCode(Integer code) {
        for (AppSourceEnum appSourceEnum : AppSourceEnum.values()) {
            if (appSourceEnum.getCode() == code) {
                return appSourceEnum;
            }
        }
        return null;
    }

    public static AppSourceEnum getByMessage(String msg) {
        for (AppSourceEnum appSourceEnum : AppSourceEnum.values()) {
            if (appSourceEnum.getMessage().equalsIgnoreCase(msg)) {
                return appSourceEnum;
            }
        }
        return null;
    }

}
